package com.zmn.oms.admin.controller.order;

import com.zmn.common.constant.GlobalConsts;
import com.zmn.common.dictionary.GlobalDict;
import com.zmn.common.dto.LoginStaff;
import com.zmn.common.utils.number.NumberUtil;
import com.zmn.mcc.cas.web.StaffAdminService;
import com.zmn.oms.admin.controller.OmsBaseController;
import com.zmn.oms.business.interfaces.purpose.OrderPurposeBService;
import com.zmn.oms.common.dto.ResultDTO;
import com.zmn.oms.common.vo.KVDict;
import com.zmn.oms.model.entity.purpose.OrderPurpose;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

/**
 * 类描述：意向单
 *
 * @author liuying
 * @date 2019/03/07 11:04
 */
@Slf4j
@Controller
@RequestMapping("/order/purpose")
public class OrderPurposeController extends OmsBaseController {

    @Autowired
    private OrderPurposeBService orderPurposeBService;

    /**
     * 新增订单
     *
     * @return
     */
    @RequestMapping(value = "add")
    public ModelAndView add() {
        ModelAndView mav = new ModelAndView("purpose/add");
        // 性别
        mav.addObject("gender", super.dictModel2KVDict(GlobalDict.getGenderList()));
        // 渠道列表 1不禁用，2禁用
        mav.addObject("channelList", super.getAllChannelListByPermit(GlobalConsts.PLAT_MARK_ZMN, null, GlobalConsts.LEVEL_2, null));
        // 服务分类
        mav.addObject("servCategList", super.getShowServCategList());
        // 产品
//        List<KVDict> servProductList = super.getServProductList(GlobalConsts.PLAT_MARK_ZMN, null, GlobalConsts.YES, false);
//        servProductList.addAll(super.getServProductListByDisableShowProduct(GlobalConsts.PLAT_MARK_ZMN, null));// 加入禁用前台产品关联的后台产品
//        mav.addObject("servProductList", servProductList);
        // 品牌
        mav.addObject("brandList", super.getBrandList());
        // 省份
        mav.addObject("provinceList", super.getAllProvinceList());
        // 城市ID
        mav.addObject("cityList", super.getAllCityList());
        return mav;
    }

    /**
     * 新增意向单
     *
     * @return
     */
    @RequestMapping(value = "save", method = RequestMethod.POST)
    @ResponseBody
    public ResultDTO saveOrder(@RequestBody OrderPurpose orderPurpose) {
        try {
            logger.debug("新增意向单：{}", orderPurpose);
            orderPurpose.setProductId(orderPurpose.getShowProductId());
            orderPurpose.setCreater(super.getLoginStaff().getRealName());
            orderPurposeBService.insertOrderPurpose(orderPurpose);
            return ResultDTO.success();
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            return ResultDTO.fail(e.getMessage());
        }
    }

}
